package com.art.coconut.example.service;

import cn.hutool.core.date.DateTime;
import com.art.coconut.change.BaseChangePojo;
import com.art.coconut.change.FinalChangePojo;
import com.art.coconut.core.Coconut;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import com.art.coconut.example.model.Business;
import com.art.coconut.example.model.BusinessDetail;
import com.art.coconut.example.model.Employee;


import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Component
public class ProcessService {

    public void testCoconut() throws IllegalAccessException, InstantiationException {

        Business b1 = buildSrcBusiness();
        Business b2 = buildDstBusiness();
        List<BaseChangePojo> baseChangePojoList =  Coconut.processObject(b1, b2);
        List<FinalChangePojo> finalChangePojoList = Coconut.getFinaChangeList(null, "BUSINESS", baseChangePojoList, false);
        List<BaseChangePojo> finalBaseChangeProperty = Coconut.getFinalChangeProperty(null, "BUSINESS", baseChangePojoList, false);
        Coconut.prettyPrint(baseChangePojoList, false);
    }

    public Business buildBusiness(String id, String bizNum, BigDecimal lmt, List<BusinessDetail> dtlList){
        return Business.builder().id(id).bizNum(bizNum).lmt(lmt).businessDetailList(dtlList).build();
    }
    public BusinessDetail buildDtl(String id, String bizId,BigDecimal lmt, List<Employee> employeeList){
        return BusinessDetail.builder().id(id).bizId(bizId).lmt(lmt).employeeList(employeeList).build();
    }

    public Employee buildEle(String id, String detailId, Date birth){
        return Employee.builder().id(id).detailID(detailId).birthDay(birth).build();
    }

    public Business buildSrcBusiness(){
        List<Employee> employeeList = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        calendar.set(2025,1,20);
        employeeList.add(buildEle("1","1", calendar.getTime()));
        List<BusinessDetail> businessDetails = new ArrayList<>();
        businessDetails.add(buildDtl("1", "1", BigDecimal.valueOf(100.00d), employeeList));
        return buildBusiness("1","biz1234",BigDecimal.valueOf(111.00d), businessDetails);
    }

    public Business buildDstBusiness(){
        List<Employee> employeeList = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        calendar.set(2025,2,20);
        employeeList.add(buildEle("1","1", calendar.getTime()));
        List<BusinessDetail> businessDetails = new ArrayList<>();
        businessDetails.add(buildDtl("1", "1", BigDecimal.valueOf(110.00d), employeeList));
        return buildBusiness("1","biz222",BigDecimal.valueOf(121.00d), businessDetails);
    }
}
